import IndexService from "../../service/IndexService";
import arrayUtil from "../../basic/utils/arrayUtil";

const initState = {
    selectPoint: null,
    hColorPixel: {
        '10_10': '#ff0',
        '20_20': '#0f9'
    },
    pixelData: [],

    v: 0
};

const indexService = new IndexService();

const fun = {
    setSelectPoint(preState, point) {
        preState.selectPoint = point;
        return preState;
    },
    deleteHColorByXy(preState, {x, y}) {
        delete preState.hColorPixel[`${x}_${y}`]
        return preState;
    },
    addHColorByXy(preState, {x, y, color}) {
        preState.hColorPixel[`${x}_${y}`] = color;
        return preState;
    },
    initPixelData(preState, data) {
        preState.pixelData = data;
        return preState;
    },
    moveIndexForOpenList(preState, data) {
        let {dragMyIndex, dragTargetIndex} = data;
        let {openList} = preState;
        let dragMyTab = openList[dragMyIndex];
        openList.splice(dragMyIndex, 1)
        openList.splice(dragTargetIndex, 0, dragMyTab);
        preState.openList = openList;
        return preState;
    },
}
export default function fileListReducer(preState = initState, action) {
    const {type, data} = action;
    preState.v++;
    if (fun[type]) {
        return Object.assign({}, fun[type](preState, data));
    } else {
        return preState;
    }
}
